package com.mtf.handler;

import com.mtf.common.vo.Result;
import com.mtf.handler.exception.BusinessException;
import com.mtf.handler.exception.MqRepeatConsumeException;
import com.mtf.handler.exception.RocketMqException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author matengfei
 * @Date 2024/3/15 14:37
 * @PackageName:com.mtf.handler
 * @ClassName: GlobalExceptionHandler
 * @Description: TODO
 * @Version 1.0
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(MqRepeatConsumeException.class)
    @ResponseBody
    public Result<?> handleMqRepeatConsumeException(MqRepeatConsumeException mqRepeatConsumeException){
        return Result.error(mqRepeatConsumeException.getMessage());
    }

    @ExceptionHandler(BusinessException.class)
    @ResponseBody
    public Result<?> handleBusinessException(BusinessException businessException){
        return Result.error(businessException.getMessage());
    }

    @ExceptionHandler(RocketMqException.class)
    @ResponseBody
    public Result<?> handleRocketMqException(RocketMqException rocketMqException){
        return Result.error(rocketMqException.getMessage());
    }
}
